/*
*	string.c - Operacions per a tractament de cadenes de caracters
*
*/

#include <string.h>

char * itoa(int value,int base) 
{
  static char buf[32] = {0};
  int i = 30;
  if (value == 0)
    return "0";
  for(;value&&i;--i,value/=base)
    buf[i] = "0123456789ABCDEF"[value % base];
  return &buf[i+1];
}
	
int strlen(const char * str)
{
	int lenght = 0;
	while (str[lenght] != '\0') ++lenght;
	return lenght-1;
}

int strcmp(const char *s1, const char *s2)
{
  int ret = 0;
  while (!(ret = *(unsigned char *) s1 - *(unsigned char *) s2) && *s2) ++s1, ++s2;
  if (ret < 0)
    ret = -1;
  else if (ret > 0)
    ret = 1 ;
  return ret;
}

void strcopy(char *s1,const char *s2)
{
  int i;
  for(i=0; s2[i] != '\0'; i++)
    s1[i]=s2[i];
  s1[i]='\0';
}
